package net.oschina.dajiangnan.wx.process.mp.tools;

import net.oschina.dajiangnan.wx.util.HttpTookit;
import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSON;
import net.oschina.dajiangnan.wx.constants.DynamicValue;
import net.oschina.dajiangnan.wx.process.mp.json.Result;


public class Menu {

    private static final String urlPrefix = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=";
    
    private static Logger logger = Logger.getLogger(Menu.class);
    
    public static void define(String menu_desc){
        new Thread(){
        	private String menu_desc;
			public Thread setMenu_desc(String menu_desc) {
				this.menu_desc = menu_desc;
				return this;
			}
			public void run(){
            	String respContent = new HttpTookit().doPost(urlPrefix + DynamicValue.getAccessToken(), menu_desc,null,null,"UTF-8");
                Result result = JSON.toJavaObject(JSON.parseObject(respContent), Result.class);
                if(Integer.parseInt(result.getErrcode()) == 0){
                    logger.debug("菜单创建成功");
                }else{
                    logger.debug("菜单创建失败 , result = " + result);
                }
            }
        }.setMenu_desc(menu_desc).start();
    }
}
